﻿function getCookie() {
    return localStorage.access_token;
}

try {
    $.ajaxPrefilter(function( options ) {
        if (!options.beforeSend) {
            options.beforeSend = function (xhr) {
                xhr.setRequestHeader('Authorization', getCookie());
            }
        }
    });
}catch(e) {

}

try {
    window.sessionTip = false;
    $.ajaxSetup({
        complete: function(xhr){
            if(!!xhr.responseJSON && 501 == xhr.responseJSON.code) {
                window.location.href = "/";
            }
        }
    });
}catch(e) {

}

try {
	setExtHeaders("Authorization", getCookie());
    Ext.Ajax.addListener("requestcomplete", function(self, xhr) {
        setExtHeaders("Authorization", getCookie());
    });
}catch(e) {
}

/**
 * 设置Ext headers
 **/
function setExtHeaders(key, value) {
    var headers = Ext.Ajax.getDefaultHeaders();
    if(null == headers) {
        headers = {};
    }
    headers[key] = value;
    Ext.Ajax.setDefaultHeaders(headers);
}
